using System.Globalization;
using UnityEngine;
using UnityEngine.UI;

namespace NL.Advanced.Binding
{
    public class UIBinding_Outline : UIBinding
    {
        public Outline _TrgOutline;

        protected override void SetComponentValue()
        {
            if (_TrgOutline == null)
            {
                _TrgOutline = this.GetComponent<Outline>();
            }

            if (_TrgOutline != null)
            {
                if (Value.IndexOf(';') == -1)
                {
                    int colorVal = 0;
                    if (int.TryParse(Value, NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo, out colorVal))
                    {
                        _TrgOutline.effectColor = new Color((colorVal >> 16 & 0xFF) / 255f, (colorVal >> 8 & 0xFF) / 255f, (colorVal & 0xFF) / 255f);
                    }
                }
                else
                {
                    if (Values.Length > 0)
                    {
                        int colorVal = 0;
                        if (int.TryParse(Values[0], NumberStyles.HexNumber, NumberFormatInfo.CurrentInfo, out colorVal))
                        {
                            _TrgOutline.effectColor = new Color((colorVal >> 16 & 0xFF) / 255f, (colorVal >> 8 & 0xFF) / 255f, (colorVal & 0xFF) / 255f);
                        }
                    }
                    if (Values.Length > 2)
                    {
                        int effDX = 0;
                        int effDY = 0;
                        if (int.TryParse(Values[1], out effDX) && int.TryParse(Values[2], out effDY))
                        {
                            _TrgOutline.effectDistance = new Vector2(effDX, effDY);
                        }
                    }
                }

                //_TrgText.color = Color.white
            }
        }
    }
}

